package com.captain.special.二叉树.简单;

import com.captain.leetcode.TreeNode;

/**
 * Des:
 * TODO 过两天需要重新写
 *
 * @author XL
 * @Date 2022/5/8 19:36
 */
public class 合并二叉树617 {
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        return recur(root1, root2);
    }

    public TreeNode recur(TreeNode n1, TreeNode n2) {
        if (n1 == null) {
            return n2;
        }
        if (n2 == null) {
            return n1;
        }
        //如果两个都不为null,则为节点之和
        TreeNode n3 = new TreeNode(n1.val + n2.val);
        n3.left = recur(n1.left, n2.left);
        n3.right = recur(n1.right, n2.right);
        return n3;
    }
}
